package com.example.controller.admin;

import com.example.common.Result;
import com.example.entity.DTO.StudentDetailDTO;
import com.example.entity.Student;
import com.example.service.admin.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 获取全部学生详细信息
     */
    @GetMapping("/selectAllStudent")
    public Result selectAllStudent(@RequestParam(defaultValue = "") String studentName,
                                   @RequestParam(defaultValue = "") String className,
                                   @RequestParam(defaultValue = "") String majorName) {
        List<StudentDetailDTO> studentDetailDTOS = studentService.selectAllStudent(studentName, className, majorName);
        return Result.success(studentDetailDTOS);
    }

    /**
     * 根据学号获取单个学生信息
     */
    @GetMapping("/selectStudent")
    public Result selectStudent(@RequestParam(defaultValue = "") String username) {
        Student student = studentService.selectStudent(username);
        return Result.success(student);
    }

    /**
     * 添加学生
     */
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Student student) {
        studentService.addStudent(student);
        return Result.success();
    }

    /**
     * 更新学生信息
     */
    @PutMapping("/updateStudent")
    public Result update(@RequestBody Student student) {
        studentService.updateStudent(student);
        return Result.success();
    }

    /**
     * 删除学生
     */
    @DeleteMapping("/deleteStudent/{id}")
    public Result deleteStudent(@PathVariable Integer id) {
        studentService.deleteStudent(id);
        return Result.success();
    }
}
